﻿package mortal.game.view.guildWar
{
    import Message.Public.*;
    import __AS3__.vec.*;
    import com.gengine.global.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.component.window.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.rules.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.button.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.guild.otherpanel.*;
    import mortal.game.view.guildNew.data.*;
    import mortal.game.view.vip.panel.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class GuildWarEnterWindowNew extends BaseWindow
    {
        private var signMaxValue:int = 1;
        private var _info:SGuildWarInfo;
        private var _btnOpenExploitShop:GButton;
        private var _tfExploit:GTextFiled;
        private var _rewardItemList:Vector.<BaseItem>;
        private var _enterBtn:GLabelButton;
        private var _bmpEnter:GImageBitmap;
        private var _tfNum:GTextFiled;
        private var _sendMail:GButton;
        private static var _instance:GuildWarEnterWindowNew;

        public function GuildWarEnterWindowNew(param1:ILayer = null)
        {
            this._rewardItemList = new Vector.<BaseItem>;
            super(param1);
            setSize(735, 530);
            title = Language.getString(11401);
            return;
        }// end function

        override protected function addWindowLine() : void
        {
            _windowLine = UIFactory.bg(0, 0, -1, -1, this, ImagesConst.SmallWindowBgLine);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            var _loc_5:BaseItem = null;
            super.createDisposedChildrenImpl();
            if (Global.isDebugModle)
            {
                this.signMaxValue = 1;
            }
            else
            {
                this.signMaxValue = 5;
            }
            pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.GuildWarEnterNewBg, 9, 38, this));
            var _loc_1:* = UICompomentPool.getUICompoment(VipOpenTipsPanel);
            _loc_1.move(62, 288);
            _loc_1.resetLevelTextPos(136, 9, 135, 9);
            _loc_1.resetValueTextPos(286, 9, 294, 9);
            _loc_1.bgUrl = ImagesConst.vipOpenTipsBg_long;
            _loc_1.valueType = VipOpenTipsPanel.numberValue;
            _loc_1.vipType = EVipRecordType._EVipRecordTypeGuildWarExploit;
            this.addChild(_loc_1);
            pushUIToDisposeVec(_loc_1);
            pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.GuildWarEnterNewRightBg, 510, 37, this));
            pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.GuildWarEnterNewDes, 522, 41, this));
            var _loc_2:* = UIFactory.gTextField("", 521, 80, 195, 100, this, GlobalStyle.textFormatBai.setLeading(4).setSize(14).setBold(true).setLetterSpacing(1), true);
            _loc_2.multiline = true;
            _loc_2.wordWrap = true;
            _loc_2.htmlText = Language.getString(11402);
            pushUIToDisposeVec(_loc_2);
            pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.GuildWarEnterNewExploit, 522, 230, this));
            this._btnOpenExploitShop = UIFactory.gButton(Language.getString(11403), 528, 260, 100, 28, this, "GreenLinkButtonSize14");
            this._tfExploit = UIFactory.gTextField(Language.getStringByParam(11404, "0"), 535, 287, 180, 26, this, GlobalStyle.textFormatHuang2.setSize(15).setBold(true));
            pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.GuildWarEnterNewRewards, 522, 326, this));
            this._enterBtn = UIFactory.gLabelButton(null, GLabelButton.gLoadingButton, ResFileConst.TaskContinue, 566, 439, 103, 40, this);
            this._bmpEnter = UIFactory.gImageBitmap(ImagesConst.GuildWarIWantSingUp, 582, 450, this);
            this._tfNum = UIFactory.gTextField("[0/" + this.signMaxValue + "]", 527, 493, 200, 24, this, GlobalStyle.textFormatHuang2.setSize(13));
            this._tfNum.mouseEnabled = false;
            this._sendMail = UIFactory.gButton(Language.getString(11405), 575, 500, 80, 28, this, "GreenLinkButtonSize14");
            this._sendMail.visible = false;
            var _loc_3:* = DailyRewardConfig.instance.getRewardByCode(GameConst.GuildWarDailyRewardCode);
            var _loc_4:int = 0;
            while (_loc_4 < _loc_3.length)
            {
                
                _loc_5 = UIFactory.getUICompoment(BaseItem, 530 + 44 * _loc_4, 367, this);
                _loc_5.itemData = _loc_3[_loc_4];
                _loc_5.setItemStyle(ItemStyleConst.Small, ImagesConst.PackItemBg, 2, 2);
                this._rewardItemList.push(_loc_5);
                _loc_4++;
            }
            this._btnOpenExploitShop.configEventListener(MouseEvent.CLICK, this.onClickShop);
            this._enterBtn.configEventListener(MouseEvent.CLICK, this.onClickEnter);
            this._sendMail.configEventListener(MouseEvent.CLICK, this.onClickSendMail);
            NetDispatcher.addCmdListener(ServerCommand.ExploitUpdate, this.onExploitUpdate);
            return;
        }// end function

        private function onClickEnter(event:MouseEvent) : void
        {
            if (this._info)
            {
                if (this._info.isOpen)
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.GuildWarRequestEnter));
                }
                else if (this._info.guildSignUp >= this.signMaxValue)
                {
                    MsgManager.showRollTipsMsg(Language.getString(11406));
                }
                else if (this._info.hasSignUp)
                {
                    MsgManager.showRollTipsMsg(Language.getString(11407));
                }
                else
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.GuildWarRequestSignUp));
                }
            }
            return;
        }// end function

        private function onClickShop(event:MouseEvent) : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.NPC_OpenNpcShop, ShopType.Exploit));
            return;
        }// end function

        private function onClickSendMail(event:MouseEvent) : void
        {
            if (Cache.instance.guild.selfGuildInfo.baseInfo.level < 2)
            {
                MsgManager.showRollTipsMsg(Language.getString(11408));
                return;
            }
            if (!GuildConst.hasPermissions(GuildConst.SendGuildMail))
            {
                MsgManager.showRollTipsMsg(Language.getString(11409));
                return;
            }
            GuildMailPanel.instance.popUp();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._btnOpenExploitShop.dispose(param1);
            this._btnOpenExploitShop = null;
            this._tfExploit.dispose(param1);
            this._tfExploit = null;
            EffectManager.glowFilterUnReg(this._enterBtn);
            this._tfNum.dispose(param1);
            this._tfNum = null;
            var _loc_2:int = 0;
            while (_loc_2 < this._rewardItemList.length)
            {
                
                this._rewardItemList[_loc_2].dispose(param1);
                _loc_2++;
            }
            this._rewardItemList.length = 0;
            this._enterBtn.dispose(param1);
            this._enterBtn = null;
            this._bmpEnter.dispose(param1);
            this._bmpEnter = null;
            this._sendMail.dispose(param1);
            this._sendMail = null;
            this._info = null;
            NetDispatcher.removeCmdListener(ServerCommand.ExploitUpdate, this.onExploitUpdate);
            super.disposeImpl(param1);
            return;
        }// end function

        protected function onExploitUpdate(param1) : void
        {
            this._tfExploit.text = Language.getStringByParam(11404, Cache.instance.role.money.exploit.toString());
            return;
        }// end function

        public function updateGuildWarInfo(param1:SGuildWarInfo) : void
        {
            this._info = param1;
            if (GuildNewUtil.canSendGuildMail(false))
            {
                this._enterBtn.y = 434;
                this._bmpEnter.y = 445;
                this._tfNum.y = 480;
                this._sendMail.y = 497;
                this._sendMail.visible = true;
            }
            else
            {
                this._enterBtn.y = 439;
                this._bmpEnter.y = 450;
                this._tfNum.y = 493;
                this._sendMail.visible = false;
            }
            var _loc_2:* = Cache.instance.guild.selfGuildInfo.guildWarStar;
            var _loc_3:* = Cache.instance.guild.selfGuildInfo.baseInfo.score;
            this._info.star = _loc_2;
            this._tfExploit.text = Language.getStringByParam(11404, Cache.instance.role.money.exploit.toString());
            this._enterBtn.enabled = true;
            EffectManager.glowFilterUnReg(this._enterBtn);
            if (param1.guildSignUp >= this.signMaxValue)
            {
                this._tfNum.htmlText = Language.getStringByParam(11410, this.signMaxValue.toString(), this.signMaxValue.toString());
            }
            else
            {
                this._tfNum.htmlText = Language.getStringByParam(11411, param1.guildSignUp.toString(), this.signMaxValue.toString());
            }
            if (param1.isOpen)
            {
                this._bmpEnter.imgUrl = ImagesConst.GuildWarEnterNewEnter;
                if (param1.guildSignUp >= this.signMaxValue)
                {
                    EffectManager.glowFilterReg(this._enterBtn, [FilterConst.chatTipsFilter], 0.6, 10, 1);
                    this._tfNum.htmlText = Language.getStringByParam(11412, this.signMaxValue.toString());
                }
                else
                {
                    this._tfNum.htmlText = Language.getStringByParam(11413, this.signMaxValue.toString());
                }
            }
            else if (param1.guildSignUp >= this.signMaxValue)
            {
                this._bmpEnter.imgUrl = ImagesConst.GuildWarEnterWaitNew;
                this._enterBtn.enabled = false;
            }
            else if (param1.hasSignUp)
            {
                this._bmpEnter.imgUrl = ImagesConst.GuildWarIWantSingUp;
                this._enterBtn.enabled = false;
            }
            else
            {
                this._bmpEnter.imgUrl = ImagesConst.GuildWarIWantSingUp;
                EffectManager.glowFilterReg(this._enterBtn, [FilterConst.chatTipsFilter], 0.6, 10, 1);
            }
            return;
        }// end function

        public static function get instance() : GuildWarEnterWindowNew
        {
            if (!_instance)
            {
                _instance = new GuildWarEnterWindowNew;
            }
            return _instance;
        }// end function

        public static function hasInstance() : Boolean
        {
            return _instance != null;
        }// end function

    }
}
